<template>
  <el-dialog title="设置分类" width="30%" :visible.sync="visit" @close="close()" @open="getList()">
    <el-form :model="form" :rules="rules" ref="typeForm" label-width="100px" class="demo-ruleForm">
      <el-form-item label="分类" prop="classify_ids">
        <el-select v-model="form.classify_ids" multiple placeholder="请选择" style="width:80%" clearable @change="$forceUpdate()">
          <el-option v-for="item in list" :key="item.id" :label="item.name" :value="item.id">
          </el-option>
        </el-select>
      </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="close()">取 消</el-button>
      <el-button type="primary" @click="submit()">确 定</el-button>
    </span>
  </el-dialog>
</template>

<script>
import affiliateMerchantApi from '@/api/affiliateMerchantApi.js'
export default {
  data () {
    return {
      form: {},
      list: [],
      rules: {
      }
    }
  },
  props: {
    show: {
      type: Boolean,
      default: false
    },
    shop_id: {
      type: Number | String,
    }
  },
  computed: {
    visit: {
      set (val) {
        this.$emit("update:show", val)
      },
      get () {
        return this.show
      }
    }
  },
  methods: {
    getList () {
      affiliateMerchantApi.classifyList().then(res => {
        if (res && res.data.code == 200) {
          this.list = res.data.list
        }
      })
    },
    close () {
      this.form = {};
      this.$refs['typeForm'].resetFields()
      this.visit = false
    },
    submit () {
      this.$refs.typeForm.validate((valid) => {
        if (valid) {
          this.form.shop_id = this.shop_id;
          affiliateMerchantApi.setClassify(this.form).then(res => {
            if (res && res.data.code == 200) {
              this.$message.success('设置成功！');
              this.$emit('change')
            }
            this.close()
          })
        }
      })
    }
  }
}
</script>

<style>
</style>
